<h3 class="page-header"><%= page_title %></h3>

<div class="row">
  <div class="col-md-7" id="ssp_report_form">
    <%= simple_form_for(@report) do |f| %>
      <%= f.error_messages %>

      <%= f.input :publish_at, as: :date_picker %>

      <%= f.input :user_id, collection: Ssp::User.where(admin: [false, nil]), input_html: { class: 'select2' }, label_method: :nickname if current_user.admin %>

      <% @report.report_items.new if @report.report_items.empty? %>

      <div class="row">
        <%= f.fields_for :report_items, Ssp::ReportItem.new do |ff| %>
          <%= ff.label :commodity_type, class: 'col-md-3' %>
          <%= ff.label :commodity_id, class: 'col-md-3' %>
          <%= ff.label :price, class: 'col-md-3' %>
          <%= ff.label :count, class: 'col-md-3' %>
        <% end %>
      </div>

      <%= f.fields_for :report_items do |ff| %>
        <%= render 'report_item_fields', f: ff %>
      <% end %>

      <div class="pull-right">
        <%= link_to_add_association "添加条目", f, :report_items, class: "btn btn-default add-button" %>
        <%= f.button :submit, "保存", class: "btn-primary" %>
      </div>
    <% end %>
  </div>
</div>

<script type="text/javascript">
  $("#ssp_report_form").on("cocoon:after-insert", function(event, item) {
    $(item).find('.select2').select2({
      theme: 'bootstrap',
      language: 'zh-CN'
    })
  });
</script>
